package com.iotteam.androidbase.moudules.login.view;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.iotteam.androidbase.R;
import com.iotteam.androidbase.base.BaseActivity;
import com.iotteam.androidbase.base.ToolbarActivity;
import com.iotteam.androidbase.commen.utils.ToastUtil;
import com.iotteam.androidbase.moudules.login.model.LoginInfo;
import com.iotteam.androidbase.moudules.login.presenter.ILoginPresener;
import com.iotteam.androidbase.moudules.login.presenter.LoginPresenterCompl;

import static android.icu.lang.UCharacter.GraphemeClusterBreak.L;
import static com.iotteam.androidbase.R.id.btn_login;
import static com.iotteam.androidbase.R.id.tv_regist;

/**
 * Created by lidechen on 5/3/17.
 */

public class LoginActivity extends ToolbarActivity implements ILoginView ,View.OnClickListener{

    private TextView mNameText;
    private TextView mPwdText;
    private Button mLoginBtn;
    private ILoginPresener mLoginPresener;
    private View mRegistView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mNameText = (TextView) findViewById(R.id.edit_text_name);
        mPwdText = (TextView) findViewById(R.id.edit_text_password);
        mLoginBtn = (Button) findViewById(btn_login);
        mRegistView = findViewById(tv_regist);

        mLoginBtn.setOnClickListener(this);
        mRegistView.setOnClickListener(this);

        mLoginPresener = new LoginPresenterCompl(this);
    }

    public static void launch(Context context) {
        context.startActivity(new Intent(context, LoginActivity.class));
    }

    @Override
    public String getMobile() {
        return mNameText.getText().toString().trim();
    }

    @Override
    public String getPassword() {
        return mPwdText.getText().toString().trim();
    }

    @Override
    public void finishView() {
        finish();
    }

    @Override
    public void showError(String err) {
        ToastUtil.showLong(err);
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_login;
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if(id == R.id.btn_login){
            mLoginPresener.doLogin();
        }else if(id == R.id.tv_regist){
            RegistActivity.launch(LoginActivity.this);
        }
    }
}
